Repository navigation
Add scoped companion history access and stable playback identity - #3
Open
303inmyheart wants to merge 2 commits into
Open
303inmyheart wants to merge 2 commits into
303inmyheart wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and resulting behavior
A read-only companion can poll current playback, but it cannot safely distinguish key rotation from an account/instance change or read existing watch history without receiving a normal login token. Current presence also lacks channel identity, live status and playback speed.
This adds a scoped, pull-based companion API to the Go server's
devbranch. The companion requests data and the server responds through the existing HTTP API; there are no callbacks, extra ports, new services or new Go dependencies.API changes
GET /presence/identityinstanceId, exact owning user/profileaccountId, and currentscopesGET /presence/now-playingchannelId,channelUrl,isLive,playbackSpeedGET /presence/history?limit=100&cursor=...history:readPUT /presence/keys/{id}POST /presence/keysoptionally acceptsscopes. Omitting them retains the originalpresence:readpermission. Existing metadata keeps the legacyscopefield and adds the completescopesarray. Both normal and/api-prefixed routes remain supported.Owner opt-in for an existing key:
{ "scopes": ["presence:read", "history:read"] }Sending only
presence:readrevokes history access without replacing the token.Privacy and authorization
presence_scope_requiredfor history.Cache-Control: no-store; no access tokens, names or email addresses are added to the identity response.Playback and channel handling
The existing authenticated
/sessions/playback/startand/progressrequests accept the four optional metadata fields. Unknown live status/speed remainnull; a missing duration does not imply live playback. Channel URLs are normalized, and provider IDs are extracted only from unambiguous supported URLs. YouTube handles and Twitch logins are not presented as immutable IDs.For older clients, channel identity can be recovered from the same account's saved record for the exact currently reported video. Channels are never matched by display name, and no provider requests are made for this enrichment.
Partial progress retains metadata for the same device/video within the existing presence TTL, even with admin session tracking disabled. Starting/changing a video resets old metadata; explicit false/default values are respected. A stop from another device no longer clears the current device's presence. Account deletion clears the additional in-memory playback state.
History semantics and migration
History uses descending
watchedAt/idkeyset pagination, including records sharing a timestamp. FollownextCursoruntilnull; page size is 1–1000. Pages retain their initial upper timestamp bound, so newer playback does not shift offsets. Concurrent deletion/backdated imports are not an immutable snapshot. The endpoint exposes stored records and does not manufacture completed views or recreate deleted/unrecorded history.History duration/progress remain in seconds; playback positions/durations and history timestamps use milliseconds.
The normal startup migration adds:
presence_keys.history_read NOT NULL DEFAULT FALSE;go_instance_identitytable initialized once with a random UUID;No users, keys or history are deleted/replaced. Identity survives URL changes, key rotation, container restarts and database restore. A separately operated database clone needs an administrator-assigned new identity, documented in the guide. The existing generic
TYPE_TYPE_INSTANCE_IDpush label is unchanged.Validation performed
All accounts, tokens, media and playback reports used for these checks were synthetic. No live instance credentials or personal playback data are included.
go vet ./...andgo test -race -count=1 ./..., with disposable PostgreSQL 17 and Redis 7 as the protocol-compatible test cache, passed across all packages.go test -race -count=2 ./internal/auth ./internal/api ./internal/dbpassed. The existing account-deletion test now uses unique fixture IDs and cleans up its unaffected control account, fixing a failure on repeated runs.govulncheckfound no vulnerabilities. Changed YAML parsed successfully and all 20 new/transitive OpenAPI references resolved.The upstream pull-request workflow is awaiting maintainer approval for this external contribution (run); the independent fork workflow above has passed.
Client follow-up and limits
This is a server-only change. The inspected Android playback DTO does not send the new metadata fields. The inspected TV
RemotePresence.playbackStartskips non-positive-duration media, including live streams. Those clients must send their actual live playback and speed through the existing session requests before live presence can work end to end; a stream list or extraction request cannot prove watching.The companion's consumption of the new identity/history/metadata, actual Android/TV live playback after client updates, and ARM64 runtime behavior remain integration checks. No real Discord-profile test is claimed by this PR.
Full request/response semantics, examples, migration and the client follow-up are in docs/companion-api.md, with schemas in
api/openapi/paths/presence.yamlandapi/openapi/paths/session-playback.yaml.